﻿/******************************************************************************
 *  作者：       scott
 *  创建时间：   2012/3/2 19:52:54
 *
 *
 ******************************************************************************/

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using EasyMvcBlog.DTO;
using EasyMvcBlog.Service;

namespace EasyMvcBlog.CustomerEngine
{
    /// <summary>
    /// controller基类
    /// 目的：
    ///     1.主题选择
    /// </summary>
    public abstract class BaseController : Controller
    {
        protected override void Execute(System.Web.Routing.RequestContext requestContext)
        {
            // 将主题信息存储到本次request中
            //TODO:从数据库中去除主题
            requestContext.HttpContext.Items["themeName"] = "Simple";

            //允许预览主题
            var previewTheme = requestContext.HttpContext.Request.QueryString["theme"];
            if (!string.IsNullOrEmpty(previewTheme))
            {
                requestContext.HttpContext.Items["themeName"] = previewTheme;
            }

            base.Execute(requestContext);
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {

            IList<MenuDTO> orderedMenu = MenuService.GetOrderedMenu();

            BlogDTO blogModel = BlogService.GetBlogInfo();
            ViewBag.Menus = orderedMenu;
            ViewBag.Blog = blogModel;

            base.OnActionExecuting(filterContext);
        }

        protected void ShowMessage(string msg, MessageType type, int millSecond)
        {
            //ViewBag.MsgBox = string.Format("EasyMessage('{0}','{1}',{2});", msg, type.ToString(), millSecond);
            TempData["msgbox"] = string.Format("EasyMessage('{0}','{1}',{2});", msg, type.ToString(), millSecond);
        }
    }

    public enum MessageType
    {
        success,
        error
    }
}